package classification.slvm;

import java.util.HashMap;
import java.util.Set;

/**
 * This class is used to record the structure similarity between each pair of
 * xml element in DTD, or the text similarity between each pair of xml elements
 * from two xmls
 * 
 * @author eDisOn
 * 
 */
public class ElementSimilarityMatrix
{
    private HashMap<Integer, Double> elemSimiMatrix = new HashMap<Integer, Double>();
    private String                   simiMatrixID   = null;

    public ElementSimilarityMatrix()
    {
        this.simiMatrixID = "Default";
    }

    public ElementSimilarityMatrix(String initID)
    {
        this.simiMatrixID = initID;
    }

    public void addSimilarity(int firIndex, int secIndex, double similarity)
    {
        int key = (secIndex << 8) | firIndex;
        this.elemSimiMatrix.put(key, similarity);
    }

    public double getSimilarity(int firIndex, int secIndex)
    {
        int key = (secIndex << 8) | firIndex;
        if (this.elemSimiMatrix.containsKey(key))
        {
            return this.elemSimiMatrix.get(key);
        }
        else
        {
            return 0.0;
        }
    }
    
    public void setSimiMatrixID(String newID)
    {
        this.simiMatrixID = newID;
    }
    
    public String getSimiMatrixID()
    {
        return this.simiMatrixID;
    }

    public Set<Integer> keySet()
    {
        return this.elemSimiMatrix.keySet();
    }

    public boolean contains(Integer key)
    {
        return this.elemSimiMatrix.containsKey(key);
    }

    // TODO: visualization
    public void display()
    {

    }
}
